﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.CountryRegion
{
    public class CountryRegionPresenter : Presenter<ICountryRegionView>
    {
        public CountryRegionPresenter(ICountryRegionView view)
            : base(view)
        {
        }

        public void Display(string countryRegionCode)
        {
            if (countryRegionCode == null) return;

            var countryRegion = Model.GetCountryRegion(countryRegionCode);

            View.CountryRegionCode = countryRegion.CountryRegionCode;
            View.CountryRegionName = countryRegion.CountryRegionName;
            View.CreateDate = countryRegion.CreateDate;
            View.ModifiedDate = countryRegion.ModifiedDate;
            View.Description = countryRegion.Description;
            View.IsActive = countryRegion.IsActive;
        }

        public int Save(bool action)
        {
            var countryRegion = new CountryRegionModel
            {
                CountryRegionCode = View.CountryRegionCode,
                CountryRegionName = View.CountryRegionName,
                CreateDate = View.CreateDate,
                ModifiedDate = View.ModifiedDate,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (action == true)
                return Model.AddCountryRegion(countryRegion);
            else
                return Model.UpdateCountryRegion(countryRegion);
        }

        public int Delete(string countryRegionCode)
        {
            return Model.DeleteCountryRegion(countryRegionCode);
        }
    }
}
